#include <stdio.h>

/**
 *  Test suite...
 *  Tests match functions against few scenarios.
 */
int main(){
	printf("testing... \n");

	const char* pktIp = "127.0.0.1";
	const char* passRuleIp = "127.0.0.1";
	const char* failRuleIp = "127.0.0.2";
	const char* subnetPassIp = "127.0.0.25/24"; 
	const char* subnetFailIp = "127.0.0.25/32";
	const char* ruleTcp = "tcp";
	const char* ruleUdp = "udp";

	const char* passRule = "any";

	if(matchAddr(pktIp, passRuleIp)){
		printf("   passed passRuleIp\n");
	}else{
		printf("   failed passRuleIp\n");
	}

	if(matchAddr(pktIp, failRuleIp)){
		printf("   failed failRuleIp\n");
	}else{
		printf("   passed failRuleIp\n");
	}

	if(matchAddr(pktIp, subnetPassIp)){
		printf("   passed subnetPassIp\n");
	}else{
		printf("   failed subnetPassIp\n");
	}

	if(!matchAddr(pktIp, subnetFailIp)){
		printf("   passed subnetFailIp\n");
	}else{
		printf("   failed subnetFailIp\n");
	}


	if(matchAddr("notanip", passRule)){
		printf("   passed passRule\n");
	}else{
		printf("   failed passRule\n");
	}

	if(matchProto(6, ruleTcp)){
		printf("   passed protoTcp\n");
	}
	if(matchProto(17, ruleUdp)){
		printf("   passed protoUdp\n");
	}
	if(matchProto(6, "any")){
		printf("   passed protoAll\n");
	}
	if(!matchProto(6, ruleUdp)){
		printf("   passed protoFail\n");
	}
	if(!matchProto(22, ruleUdp)){
		printf("   passed protoUnknown\n");
	}	

	char* ip = "1.2.3.4";
	char retn[4];

	charToIpOctets(ip, &retn[0]);
	if(retn[0] == 1 && retn[1] == 2 && retn[2] == 3 && retn[3] == 4){
		printf("   passed charIpOctets\n");
	}else{
		printf("   failed charIpOctets\n");
	}

	char* rule = "1.2.3.3";
	char ruleoc[4];
	charToIpOctets(rule, &ruleoc[0]);	

	if(chkOctets(&retn, &ruleoc, 24)){
		printf("   passed simpleCheckOctets\n");
	}else{
		printf("   failed simpleCheckOctets\n");
	}
 	if(!chkOctets(&retn, &ruleoc, 30)){
		printf("   passed chkOctets\n");
	}else{
		printf("   failed chkOctets\n");
	}
}
